package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.ShipmentTrack;
import com.ruoyi.system.mapper.ShipmentTrackMapper;
import com.ruoyi.system.service.IShipmentTrackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 运单轨迹Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-01-16
 */
@Service
public class ShipmentTrackServiceImpl extends ServiceImpl<ShipmentTrackMapper, ShipmentTrack> implements IShipmentTrackService
{
    @Autowired
    private ShipmentTrackMapper shipmentTrackMapper;

    /**
     * 查询运单轨迹列表
     *
     * @param shipmentTrack 运单轨迹
     * @return 运单轨迹
     */
    @Override
    public List<ShipmentTrack> selectShipmentTrackList(ShipmentTrack shipmentTrack)
    {
        QueryWrapper<ShipmentTrack> queryWrapper = new QueryWrapper<>();
        
        // 运单ID
        if (StringUtils.isNotEmpty(shipmentTrack.getShipmentId()))
        {
            queryWrapper.eq("shipment_id", shipmentTrack.getShipmentId());
        }
        
        // 运单编号
        if (StringUtils.isNotEmpty(shipmentTrack.getShipmentCode()))
        {
            queryWrapper.like("shipment_code", shipmentTrack.getShipmentCode());
        }
        
        // 轨迹类型
        if (StringUtils.isNotEmpty(shipmentTrack.getTrackType()))
        {
            queryWrapper.eq("track_type", shipmentTrack.getTrackType());
        }
        
        // 状态描述
        if (StringUtils.isNotEmpty(shipmentTrack.getTrackStatus()))
        {
            queryWrapper.like("track_status", shipmentTrack.getTrackStatus());
        }
        
        // 省份
        if (StringUtils.isNotEmpty(shipmentTrack.getProvince()))
        {
            queryWrapper.like("province", shipmentTrack.getProvince());
        }
        
        // 城市
        if (StringUtils.isNotEmpty(shipmentTrack.getCity()))
        {
            queryWrapper.like("city", shipmentTrack.getCity());
        }
        
        // 操作员
        if (StringUtils.isNotEmpty(shipmentTrack.getOperator()))
        {
            queryWrapper.like("operator", shipmentTrack.getOperator());
        }
        
        // 按轨迹时间升序排列
        queryWrapper.orderByAsc("track_time");
        
        return shipmentTrackMapper.selectList(queryWrapper);
    }

    /**
     * 根据运单ID查询轨迹列表
     *
     * @param shipmentId 运单ID
     * @return 轨迹列表
     */
    @Override
    public List<ShipmentTrack> selectTrackByShipmentId(String shipmentId)
    {
        QueryWrapper<ShipmentTrack> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("shipment_id", shipmentId);
        queryWrapper.orderByAsc("track_time");
        return shipmentTrackMapper.selectList(queryWrapper);
    }
} 